#ifndef PARTICLESYSTEM_H
#define PARTICLESYSTEM_H

#include <QObject>
#include <QVector>
#include <qopengltexture.h>

//粒子的生命周期为无限长，但一旦移除屏幕范围即回收到对象池
struct Particle
{
    //采用的纹理在数组中的下标
    int texIndex;
    //初始位置
    float x0,y0,z0;
    //速度
    float xv,yv,zv;
    //加速度
    float xa,ya,za;
    //大小
    float xsize,ysize;
};
class ParticleSystemInfo
{
public:
    ParticleSystemInfo();
    ~ParticleSystemInfo();
    bool SetInitPosRange(float min_x,float min_y,float max_x,float max_y);
    bool SetVRange(float min_x,float min_y,float max_x,float max_y);
    bool SetARange(float min_x,float min_y,float max_x,float max_y);
    bool SetSizeRange(float minx,float maxx,float miny,float maxy);
    void RefreshParticle(Particle* p);
    void AddTexture(QString path);
    void DeleteTexture(int i);
    QOpenGLTexture* GetTexture(int index);
    QString GetPath(int i);
    int TextureCount();
    QString name;
    int maxCount = 500;
    //范围属性
    float min_x0,min_y0,min_z0;
    float max_x0,max_y0,max_z0;

    float max_xv,max_yv,max_zv;
    float min_xv,min_yv,min_zv;

    float max_xa,max_ya,max_za;
    float min_xa,min_ya,min_za;

    float max_xsize,max_ysize;
    float min_xsize,min_ysize;

    //锁定宽高比
    bool lockScale = true;
private:
    //粒子外观从该纹理数组中随机选取
    QVector<QOpenGLTexture*> texs;
    QVector<QString> texpath;
};
class ParticleSystem:public QObject
{
    Q_OBJECT
public:
    static const int MAX_COUNT = 1000;
    ParticleSystem();
    ~ParticleSystem();

    Particle* GetParticle();
    void ReturnParticle(Particle* p);
    ParticleSystemInfo * info = nullptr;
private:
    QVector<Particle*> pool;
};

#endif // PARTICLESYSTEM_H
